package com.niit.mobileDevide.devidemodelpatition;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Partitioner;

public class DeviceModelPartitioner extends Partitioner<Text, Text> {

    @Override
    public int getPartition(Text key, Text value, int numPartitions) {
        // 根据设备型号进行分区
        try {
            int model = Integer.parseInt(key.toString());
            if (model >= 1 && model <= 5) {
                return model - 1; // 假设设备型号从1开始
            } else {
                // 对于无效的设备型号，分配到默认分区0
                return 0;
            }
        } catch (NumberFormatException e) {
            // 如果解析失败，返回默认分区0
            return 0;
        }
    }
}